// uncomment next line to use uthreads instead of pthreads
// #define USE_UTHREAD
#ifdef USE_UTHREAD

#    include "uthread.h"

#    define THREAD_T uthread_t

#    define THREAD_CREATE(id, func, args) uthread_create(id, func, args)
#    define THREAD_JOIN(id, retval)       uthread_join(id, retval)
#    define THREAD_SELF()                 uthread_self()
#    define THREAD_EXIT(val)              uthread_exit(val)
#    define THREAD_YIELD()                uthread_yield()

#    define THREAD_MUTEX_T uthread_mutex_t

#    define THREAD_MUTEX_INITIALIZER UTHREAD_MUTEX_INITIALIZER

#    define THREAD_MUTEX_LOCK(l)     uthread_mutex_lock(l)
#    define THREAD_MUTEX_UNLOCK(l)   uthread_mutex_unlock(l)

#    define THREAD_COND_T uthread_cond_t

#    define THREAD_COND_INITIALIZER UTHREAD_COND_INITIALIZER

#    define THREAD_COND_WAIT(c, l)  uthread_cond_wait(c, l)
#    define THREAD_COND_SIGNAL(c)   uthread_cond_signal(c)

#else

#    include <pthread.h>
#    include <sys/time.h>

#    define THREAD_T pthread_t

#    define THREAD_CREATE(id, func, args) pthread_create(id, NULL, func, args)
#    define THREAD_JOIN(id, retval)       pthread_join(id, retval)
#    define THREAD_SELF()                 pthread_self()
#    define THREAD_EXIT(val)              pthread_exit(val)
#    define THREAD_YIELD()                yield()

#    define THREAD_MUTEX_T pthread_mutex_t

#    define THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER

#    define THREAD_MUTEX_LOCK(l)     pthread_mutex_lock(l)
#    define THREAD_MUTEX_UNLOCK(l)   pthread_mutex_unlock(l)

#    define THREAD_COND_T pthread_cond_t

#    define THREAD_COND_INITIALIZER PTHREAD_COND_INITIALIZER

#    define THREAD_COND_WAIT(c, l)  pthread_cond_wait(c, l)
#    define THREAD_COND_SIGNAL(c)   pthread_cond_signal(c)

#endif
